import PropTypes from 'prop-types';
import React from 'react';

import Loader from '../Loader'
import Comment from "./Comment";
import CreateComment from "./CreateComment";


const Comments = props => {
  const { comments , show ,  post , handleSubmit , user } = props;
  if (show && !comments){
    return <Loader />
  }
  return (
      <div className="comments">
        {show && [
            <div className="comments-prompt"><i className="fa fa-arrow-down" />所有评价<i className="fa fa-arrow-down" /></div>,
            ...comments.map(comment => <Comment key={comment.id} comment={comment} />),
            <CreateComment key={post.id} post={post} handleSubmit={handleSubmit} user={user} />
         ]}
      </div>
  )
}

Comment.propTypes = {
  comments: PropTypes.array,
}

export default Comments;
